package com.itheima.tlias84.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用@Bean注解,自动装配 阿里云Oss对象，实现阿里云连接对象的复用
 */
@Configuration
public class LoadOssConfig {

    @Resource
    AliyunOssConfig ossConfig;

    /**
     * 创建阿里云Oss连接信息OssBean
     * @return
     */
    @Bean("ossBean")
    public OSS createOss(){
        OSS build = new OSSClientBuilder().build(ossConfig.getEndpoint(),
                ossConfig.getAccessKeyId(), ossConfig.getSecretAccessKey());
        return build;
    }
}
